package com.centit.csgzsz.controller;

import com.centit.csgzsz.po.Csgzsz;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
 
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import com.centit.csgzsz.service.CsgzszManager;
	

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.alibaba.fastjson.JSONArray; 
import com.centit.framework.common.JsonResultUtils;
import com.centit.framework.common.ResponseMapData;
import com.centit.framework.core.controller.BaseController;
import com.centit.support.database.utils.PageDesc;

/**
 * Csgzsz  Controller.
 * create by scaffold 2020-03-10 
 * @author 脚手架，改成开发者的名字
 * T_CSGZSZ【测算规则设置表】【测算规则设置表】   
*/


@Controller
@RequestMapping("/csgzsz/csgzsz")
public class CsgzszController  extends BaseController {
	private static final Log log = LogFactory.getLog(CsgzszController.class);
	
	@Resource
	private CsgzszManager csgzszMag;	
	

    /**
     * 查询所有   T_CSGZSZ【测算规则设置表】  列表
     *
     * @param field    json中只保存需要的属性名
     * @param request  {@link HttpServletRequest}
     * @param response {@link HttpServletResponse}
     * @return {data:[]}
     */
    @RequestMapping(method = RequestMethod.GET)
    public void list(String[] field, PageDesc pageDesc, HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> searchColumn = convertSearchColumn(request);        
        
        JSONArray jsonArrayObjects = csgzszMag.listObjectsAsJson( searchColumn, pageDesc);
         
        if (null == pageDesc) {
            JsonResultUtils.writeSingleDataJson(jsonArrayObjects, response);
            return;
        }
        
        ResponseMapData resData = new ResponseMapData();
        resData.addResponseData(OBJLIST, jsonArrayObjects);
        resData.addResponseData(PAGE_DESC, pageDesc);

        JsonResultUtils.writeResponseDataAsJson(resData, response);
    }
    
    /**
     * 查询单个  T_CSGZSZ【测算规则设置表】 
	
	 * @param recId  REC_ID
     *  
     * 
     * @param response    {@link HttpServletResponse}
     * @return {data:{}}
     */
    @RequestMapping(value = "/{recId}", method = {RequestMethod.GET})
    public void getCsgzsz(@PathVariable String recId, HttpServletResponse response) {
    	
    	Csgzsz csgzsz =     			
    			csgzszMag.getObjectById( recId);
        
        JsonResultUtils.writeSingleDataJson(csgzsz, response);
    }
    
    /**
     * 新增 T_CSGZSZ【测算规则设置表】，业务只有新增的时候可用此方法，如有修改可用下面 新增或保存合并的方法
     *
     * @param csgzsz  {@link Csgzsz}
     * @return
     */
    @RequestMapping(method = {RequestMethod.POST})
    public void createCsgzsz(@Valid Csgzsz csgzsz, HttpServletResponse response) {
    	 csgzszMag.saveNewObject(csgzsz);
        JsonResultUtils.writeSingleDataJson("操作成功",response);
    }

    /**
     * 删除单个  T_CSGZSZ【测算规则设置表】 
	
	 * @param recId  REC_ID
     */
    @RequestMapping(value = "/{recId}", method = {RequestMethod.DELETE})
    public void deleteCsgzsz(@PathVariable String recId, HttpServletResponse response) {
    	
    	csgzszMag.deleteObjectById( recId);
        
        JsonResultUtils.writeSingleDataJson("操作成功",response);
    } 
    
    /**
     * 新增或保存 T_CSGZSZ【测算规则设置表】 
    
	 * @param recId  REC_ID
	 * @param csgzsz  {@link Csgzsz}
     * @param response    {@link HttpServletResponse}
     */
    @RequestMapping(value = "/{recId}", method = {RequestMethod.PUT})
    public void updateCsgzsz(@PathVariable String recId, 
    	@Valid Csgzsz csgzsz, HttpServletResponse response) {
    	
    	
    	Csgzsz dbCsgzsz  =     			
    			csgzszMag.getObjectById( recId);
        
        

        if (null != dbCsgzsz) {//如果数据库数据存在，则是更新操作
        	dbCsgzsz .copyNotNullProperty(csgzsz);//赋值页面不为空的值，小心页面空的字符串或者改写copyNotNullProperty方法，根据自己业务需要
        	csgzszMag.mergeObject(dbCsgzsz);
        } else {
             csgzszMag.saveNewObject(csgzsz);//新增,注意主键赋值 UuidUtil.getTimeBasedUuid()，填写自己的业务时间，业务操作人等信息
        }

        JsonResultUtils.writeSingleDataJson("操作成功",response);
    }
}
